﻿using System;
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SydEnergiPrototype.Model
{
    [DataContract]
    public class Address : IAddress
    {
        [DataMember]
        public string StreetName { get; set; }
        [DataMember]
        public int StreetNumber { get; set; }
        [DataMember]
        public int ZipCode { get; set; }
        [DataMember]
        public string City { get; set; }
        [DataMember]
        public string Letter { get; set; }
        [DataMember]
        public string Floor { get; set; }
        [DataMember]
        public string StairCasePosition { get; set; }

        public Address(){}

        public Address(string streetname, int streetnumber, int zipcode, string city)
            :this(streetname, streetnumber, null, null, null, zipcode, city)
        {

        }

        public Address(string streetname, int streetnumber, string letter, int zipcode, string city)
            : this(streetname, streetnumber, letter, null, null, zipcode, city)
        {

        }

        public Address(string streetname, int streetnumber, string floor, string scpos, int zipcode, string city)
            : this(streetname, streetnumber, null, floor, scpos, zipcode, city)
        {

        }

        public Address(string streetname, int streetnumber, string letter, string floor, string scpos, int zipcode, string city)
        {
            if (string.IsNullOrEmpty(streetname) || string.IsNullOrWhiteSpace(streetname))
                throw new ArgumentNullException("streetname");

            StreetName = streetname;

            if (streetnumber <= 0)
                throw new ArgumentOutOfRangeException("streetnumber");

            StreetNumber = streetnumber;

            if (zipcode < 1000 || zipcode >= 10000)
                throw new ArgumentOutOfRangeException("zipcode");

            ZipCode = zipcode;

            if (string.IsNullOrEmpty(city) || string.IsNullOrWhiteSpace(city))
                throw new ArgumentNullException("city");

            City = city;

            Letter = (letter ?? "");
            Floor = (floor ?? "");
            StairCasePosition = (scpos ?? "");
        }


        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;


            if(obj is MarkedAddress)
            {
                var ma = obj as MarkedAddress;

                return (StreetName == ma.AlteredAddress.StreetName) && (StreetNumber == ma.AlteredAddress.StreetNumber) && (ZipCode == ma.AlteredAddress.ZipCode) &&
                    (City == ma.AlteredAddress.City) && (Floor == ma.AlteredAddress.Floor) && (Letter == ma.AlteredAddress.Letter) &&
                    (StairCasePosition == ma.AlteredAddress.StairCasePosition);
            }

            Address a = obj as Address;
            if ((object) a == null)
                return false;

            return (StreetName == a.StreetName) && (StreetNumber == a.StreetNumber) && (ZipCode == a.ZipCode) &&
                    (City == a.City) && (Floor == a.Floor) && (Letter == a.Letter) &&
                    (StairCasePosition == a.StairCasePosition);
            
        }
    }
}
